#ifndef PLAYERTABLE_H
#define PLAYERTABLE_H

#include <QGraphicsObject>
#include"villagetile.h"
#include"skillbutton.h"
#include"player.h"
#include "ghost.h"

class PlayerTable;
class Ghost;
class GhostPixmap;
/*

  TileBoard:
    organizer includes 9 villageTiles

  */


class TileBoard : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit TileBoard(QGraphicsObject *parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    int test;
    const static int TILE_WIDTH = 60;
    VillageTile* getVillageTile(int x, int y){return villages[x][y];}
protected:
    VillageTile* villages[3][3];
    int getTest();
signals:
    void pressed(VillageTile*);
};

/*

  GhostSlot:
    included by GhostBoard

  */

class GhostSlot : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit GhostSlot(QGraphicsObject *parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setGhost( Ghost *ghost );

protected:
    Ghost* currentGhost;
    GhostPixmap* _ghostpix;
    GameParAnimation* ghostSetAnim;
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
signals:
    void pressed(GhostSlot*);
    void hovered(Ghost*);

};

/*

  PlayerHeadImageArea:
    included by GhostBoard

  */

class PlayerHeadImageArea : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit PlayerHeadImageArea(QGraphicsObject* parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    const static int HEAD_HEIGHT = 50;
};

/*

  PlayerStatusArea:
    included by GhostBoard

  */

class PlayerStatusArea : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit PlayerStatusArea(QGraphicsObject* parent = 0,
                              player* pl = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    const static int STATUS_HEIGHT = 150;
    player* _testPlayer;


private:
    QGraphicsPixmapItem* _playerpixmap;

};


/*

  GhostBoard(player board):
    organizer includes 3 GhostSlots, 1 PlayerHeadImageArea, 1 status bar

  */

class GhostBoard : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit GhostBoard(QGraphicsObject *parent = 0, int pn = 0,
                        player* pl = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    PlayerStatusArea* getStatusArea() {return status;}

    const static int BOARD_WIDTH = 180;
    const static int BOARD_HEIGHT = 140;

protected:
    int _pn;
    GhostSlot* slot[3];
    PlayerHeadImageArea* head;
    PlayerStatusArea* status;
signals:
    void slotPressed(GhostSlot*);
    void ghostHovered(Ghost*);
};

/*

  PlayerTable:
    Main organizer includes 4 GhostBoards, 1 TileBoard

  */

class PlayerTable : public QGraphicsObject
{
    Q_OBJECT
public:
    explicit PlayerTable(QGraphicsItem *parent = 0);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    static PlayerTable* getTablePointer();
    GhostSlot* askForSlot();
    VillageTile* askForVillageTile();
    SkillButton* askForSkillButton();

    QList<player*> playerList;
    TileBoard* getTileBorad() {return tileBoard; }

protected:
    void organizeGhostBoards();
    QEventLoop e;
    GhostBoard* board[4];
    TileBoard* tileBoard;

    SkillButton* skillButton;
    SkillButton* askSkillResultTile;
    GhostSlot* askResultSlot;
    VillageTile* askResultTile;
    PlayerIcon* _playerIcon;

    bool _respondSlot;
    bool _respondTile;
    bool _respondSkill;
signals:
    void phaseChange();
    void hoveredGhost( Ghost* );
public slots:
    void testDialog();
    void slotResult(GhostSlot*);
    void tileResult(VillageTile*);
    void skillResult(SkillButton*);
};
#endif // PLAYERTABLE_H
